<template>
	<view>
		<view class="news-item" v-for="(item,index) in news" 
		:key="index" 
		@click="clickDetail(item.id)">
			<image :src="item.imgUrl"></image>
			<view class="right">
				<view class="title">{{item.title}}</view>
				<view class="info">
					<text>发表时间：{{item.releaseDate}}</text>
					<text>浏览次数：{{item.viewCount}}</text>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		props: ['news'],
		methods:{
			clickDetail(id){
				console.log("子组件点击了查看news详情！");
				// 触发父组件的自定义事件
				this.$emit("newsClick", id);
			}
		}
	}
</script>

<style lang="scss">
	.news-item{
		display: flex;
		padding: 10rpx 20rpx;
		border-bottom: 1px solid #eee;
		image{
			min-width: 200rpx;
			max-width: 200rpx;
			height: 150rpx;
		}
		.right{
			margin-left: 15rpx;
			display: flex;
			flex-direction: column;
			justify-content: space-between;
			.title{
				font-size: 30rpx;
			}
			.info{
				font-size: 24rpx;
				text:nth-child(2){
					margin-left: 30rpx;
				}
			}
		}
	}
</style>
